<?php
namespace app\index\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;

use think\Db;

class Storemain extends HomeBase
{
	protected function _initialize(){
		parent::_initialize();
	}

	
	public function showPhoto($id=2)
    {
        $showPhoto_list = Db('slide')->where('cid',$id)->select();
        if($showPhoto_list){
            $this->apiSuccess($showPhoto_list);
        }else{
            $this->apiError('没有查到信息');
        }
    }
	/**
	*车商城首页显示品牌        
	**/
	public function brand()
	{
		$list = Db('store_classify')->where('pid',1)->page(1,6)->select();
		$this->doif($list);

	}

	/**
	*车商城首页更多品牌        
	**/
	public function brands()
	{
		$list = Db('store_classify')->where('pid',1)->select();
		$this->doif($list);

	}

	/**
	*车商城首页更多车型 (车型列表)      
	**/
	public function moreType()
	{
		$list = Db('store_classify')->where('pid',3)->select();
		$this->doif($list);
	}


	/**
	*车商城首页精选好车
	*@param   title          查询的title  		 
	*@param   pagelimit 	 每页几个      
	**/
	public function goodCars()
	{
		$pagelimit = (isset($_GET['pagelimit']) ? $_GET['pagelimit']:4);
		$title = (isset($_REQUEST['title']) ? $_REQUEST['title']:'');
		if($title){
            $map['title'] = ['like',"%{$title}%"];
        }
        $map['status'] = 1;
		$carList = Db('store_truck')->where('is_recommend',1)->where($map)->page(1,$pagelimit)->order('create_time','desc')->select();
		$i=0;
		for (; $i < count($carList); $i++) { 
			echo $carList[$i]['photo'];
			if (!$carList[$i]['photo']) {
				$carList[$i]['photo'] = unserialize($carList[$i]['photo']);
			}
		}
		$this->doif($carList);
	}

	/**
	*公共方法:将数组进行判断
	*@param  $arr		  要判断的数组
	**/
	public function doif($arr)
	{
		if($arr){
            $this->apiSuccess($arr);
        }else{
            $this->apiError('没有查到信息');
        }
	}

}